<?php


namespace app\admin\controller;

use app\facade\Upload as UploadF;

class Upload extends Base
{
    /**
     * Desc: base64图片上传
     * User: 苏鹏
     * Date: 2023/10/8
     * Time: 9:40
     * @return \think\response\Json
     */
    public function base64Img()
    {
        $img = input('base64_img');

        try{
            $data = [];
            foreach($img as $k=>$v){
                $data[] = UploadF::fileBase64($v);
            }

        }catch (\Exception $e){
            return re_error_json($e->getMessage());
        }
        return re_success_json($data);
    }


    /**
     * Desc: 文件上传
     * User: 苏鹏
     * Date: 2023/10/8
     * Time: 9:41
     * @return void
     */
    public function files()
    {
        $files = request()->file();
        try{
            validate(['image'=>'fileSize:102400|fileExt:xlsx|fileMime:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'])
                ->check($files);
            $savename = [];
            foreach($files as $file) {
                $savename[] = \think\facade\Filesystem::putFile( 'admin', $file);
            }
            dump($savename);die;
        }catch (\Exception $e){
            return re_error_json($e->getMessage());
        }
        return re_success_json();
    }
}